<!--
    Desenvolvido pela Fábrica de Software do CESUPA.
    Todos os direitos reservados.

    @author Breno Leite
-->

<ui:component xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:a4j="http://richfaces.org/a4j"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:c="http://java.sun.com/jstl/core">

    <h:form id="application-status-form">
        <table align="center">
            <tr>
                <td>
            <a4j:region id="messagearea" rendered="#{applicationStatusBean.currentMessageActive}">
                <div id="status" class="#{applicationStatusBean.currentMessage.messageType.name}">
                    <table>
                        <tr>
                            <td style="text-align:left;">
                                <img border="0"
                                     src="#{facesContext.externalContext.request.contextPath}/infrastructure/images/icons/#{applicationStatusBean.currentMessage.messageType.name}-16x16.gif"
                                     alt="#{applicationStatusBean.currentMessage.messageType} icon"/>
                            </td>
                            <td style="padding-left:10px;">
                        <h:outputText escape="false" value="#{applicationStatusBean.currentMessage.text}"/>
                        </td>
                        <td style="padding-left:10px;">
                        <h:form>
                            <h:outputLink rendered="#{!empty applicationStatusBean.currentMessage.moreInformationDisponible}"
                                          value="#" id="link">
                                <h:graphicImage title="#{tooltipmessages.ViewDetails}"
                                                url="/infrastructure/images/icons/details-16x16.gif"/>
                                <rich:componentControl for="message-details-window"
                                                       attachTo="link" operation="show"
                                                       event="onclick"/>
                            </h:outputLink>
                            <h:outputText value=" "/>
                            <a4j:commandLink id="hide-status-message-link">
                                <a4j:actionparam name="username" action="null"
                                                 value="false"
                                                 assignTo="#{applicationStatusBean.currentMessageActive}"/>
                                <a4j:support event="onclick" reRender="messagearea" />
                                <h:graphicImage url="/infrastructure/images/icons/close-16x16.gif"
                                                title="#{tooltipmessages.CloseMessage}"/>
                                <rich:effect for="hide-status-message-link"
                                             targetId="status" event="onclick"
                                             type="DropOut" params="duration:0.5" />
                            </a4j:commandLink>
                        </h:form>
                        </td>
                        </tr>
                    </table>
                </div>
            </a4j:region>
            </td>
            </tr>
        </table>

        <rich:modalPanel autosized="true" styleClass="window"
                         onshow="setFocusAtElement('application-status-form:application-status-window-close-button')"
                         id="message-details-window" height="250" width="550">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Status da aplicação"></h:outputText>
                </h:panelGroup>
            </f:facet>
            <f:facet name="controls">
                <h:panelGroup>
                    <h:form>
                        <h:commandLink title="#{tooltipmessages.CloseWindow}"
                                       id="hide-application-status-window-link">
                            <h:graphicImage alt="#{altmessages.CloseWindow}"
                                            value="/infrastructure/images/icons/close-16x16.gif"/>
                            <rich:componentControl for="message-details-window"
                                                   attachTo="hide-application-status-window-link"
                                                   operation="hide" event="onclick"/>
                        </h:commandLink>
                    </h:form>
                </h:panelGroup>
            </f:facet>
            <table border="0" width="100%" class="#{applicationStatusBean.currentMessage.messageType.name}-message-main-area">
                <tr>
                    <td width="64px">

                    </td>
                    <td style="padding:10px;">
                <h:outputText escape="false" value="#{applicationStatusBean.currentMessage.text}"/>
                </td>
                </tr>
            </table>
            <div >
                <c:if test="#{applicationStatusBean.currentMessage.details != null}">
                    <br />
                    <h:graphicImage url="/infrastructure/images/icons/arrow-down-16x16.gif"/>
                    <h3 class="section-header">#{words.Details}</h3>
                    <div class="section" style="background-image:
                         url('#{facesContext.externalContext.request.contextPath}/infrastructure/images/icons/details-32x32.gif');">
                        #{applicationStatusBean.currentMessage.details}
                    </div>
                    <br />
                </c:if>

                <c:if test="#{applicationStatusBean.currentMessage.solution != null}">
                    <br />
                    <h:graphicImage url="/infrastructure/images/icons/arrow-down-16x16.gif"/>
                    <h3 class="section-header">#{words.Solution}</h3>
                    <div class="section" style="background-image:
                         url('#{facesContext.externalContext.request.contextPath}/infrastructure/images/icons/idea-32x32.gif');">
                        #{applicationStatusBean.currentMessage.solution}
                    </div>
                    <br />
                </c:if>
            </div>
            <br />
            <div class="buttons" style="float:right;">
                <h:commandLink type="reset" id="application-status-window-close-button"
                               class="primarybutton">
                    #{words.Close}
                    <rich:componentControl for="message-details-window"
                                           attachTo="application-status-form:application-status-window-close-button"
                                           operation="hide" event="onclick"/>
                </h:commandLink>
            </div>
        </rich:modalPanel>
    </h:form>
</ui:component>